const { BrowserWindow, ipcMain, screen, dialog, webContents } = require('electron');
const fs = require('fs');
import axios from 'axios';
import rightClickData from '@/components/view_list/utils/rightclickdata.js'

let winURL
if (process.env.WEBPACK_DEV_SERVER_URL) {
    winURL = process.env.WEBPACK_DEV_SERVER_URL
} else {
    winURL = 'app://./index.html'
}
//合约窗口
let heyueListWindow
function createheyueList(parWin) {
    if (heyueListWindow) {
        heyueListWindow.focus()
        return
    }
    heyueListWindow = new BrowserWindow({
        width: 470,
        height: 340,
        modal: true,
        frame: false,
        parent: parWin, //基于窗口
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        icon: '',  // 去掉图标
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    heyueListWindow.loadURL(winURL + '#/heyuelist');
    heyueListWindow.on('close', () => {
        heyueListWindow = null
    })
    ipcMain.on('close-heyue-list', (e, v) => {
        if (v.type == 1) {
            parWin.webContents.send('select-heyue', v.val);
        }
        heyueListWindow.close()
        heyueListWindow = null
        ipcMain.removeAllListeners('close-heyue-list')
    });
}

//K线右键菜单窗口
let rightClickmneun, ishowrightClickmenu1 = true, WinloadingView, WinPar
async function createRightClickmneun(win, loadingView, value) {
    if (rightClickmneun) {
        let val = !value.x ? value : value.TypeName,
            moreX = value.x ? value.x : 0,
            moreY = value.y ? value.y : 0
        let winh = screen.getPrimaryDisplay().workAreaSize.height;
        let winxy = screen.getCursorScreenPoint()
        ishowrightClickmenu1 = true
        let bottonY = winxy.y * 1 + rightClickData[val].h * 1
        let y = bottonY > winh ? winh - rightClickData[val].h - 10 : winxy.y
        const windowBounds = win.getBounds();
        const windowRightX = windowBounds.x * 1 + windowBounds.width * 1;
        let x = winxy.x * 1 + moreX * 1 + rightClickData[val].w * 1 > windowRightX * 1 ? winxy.x - moreX - rightClickData[val].w : winxy.x * 1 + moreX * 1
        rightClickmneun.setBounds({ x: x * 1, y: y * 1 + moreY * 1, width: rightClickData[val].w * 1, height: rightClickData[val].h * 1 })
        rightClickmneun.webContents.send('right-click-menu', { x: x, y: y * 1 + moreY * 1, pidx: val });
        rightClickmneun.show()
        return
    }
    rightClickmneun = new BrowserWindow({
        width: 0,
        height: 0,
        x: 0, // 设置窗口的 x 坐标
        y: 0,
        modal: false,
        parent: win,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        icon: '',  // 去掉图标
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    rightClickmneun.hide();
    await rightClickmneun.loadURL(winURL + '#/rightClickMenu');
    WinloadingView = loadingView
    WinPar = win
    rightClickmneun.on('blur', () => {
        if (ishowrightClickmenu1) {
            hiderightClickMenu()
        }
        ishowrightClickmenu1 = false
    })
    ipcMain.on('hide-right-click-menu', (e, v) => {
        ishowrightClickmenu1 = false
        ishowrightClickmenu2 = false
        ishowrightClickmenu3 = false
        hiderightClickMenu()
    });
    ipcMain.on('open-right-click-2', (e, v) => {
        ishowrightClickmenu1 = false
        createRightClickmneun2(v)
    });
    createRightClickmneun2()
}

//K线右键菜单窗口二及菜单
let rightClickmneun2, ishowrightClickmenu2 = true
async function createRightClickmneun2(e) {
    if (rightClickmneun2) {
        let winh = screen.getPrimaryDisplay().workAreaSize.height;
        ishowrightClickmenu2 = true
        let bottonY = e.y * 1 + e.h * 1
        let y = bottonY > winh ? winh - e.h - 10 : e.y
        rightClickmneun2.setBounds({ x: e.x * 1, y: y * 1, width: e.w * 1, height: e.h * 1 })
        rightClickmneun2.webContents.send('right-click-menu-2', e);
        rightClickmneun2.show()
        return
    }
    rightClickmneun2 = new BrowserWindow({
        width: 0,
        height: 0,
        x: 0, // 设置窗口的 x 坐标
        y: 0,
        modal: false,
        frame: false,
        parent: rightClickmneun,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        icon: '',  // 去掉图标
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    rightClickmneun2.hide();
    await rightClickmneun2.loadURL(winURL + '#/rightClickMenu2');
    rightClickmneun2.on('blur', () => {
        if (ishowrightClickmenu2 && !rightClickmneun.isFocused()) {
            hiderightClickMenu()
        }
        ishowrightClickmenu2 = false
    })
    ipcMain.on('hide-right-click-menu-2', (e, v) => {
        if (rightClickmneun3.isVisible()) {
            return
        }
        ishowrightClickmenu2 = false
        ishowrightClickmenu3 = false
        rightClickmneun2.hide();
        rightClickmneun3.hide();
    });
    ipcMain.on('open-right-click-3', (event, v) => {
        ishowrightClickmenu2 = false
        createRightClickmneun3(v)
    });
    createRightClickmneun3()
}


//K线右键菜单窗口三及菜单
let rightClickmneun3, ishowrightClickmenu3 = true
async function createRightClickmneun3(e) {
    if (rightClickmneun3) {
        let winh = screen.getPrimaryDisplay().workAreaSize.height;
        ishowrightClickmenu3 = true
        let bottonY = e.y * 1 + e.h * 1
        let y = bottonY > winh ? winh - e.h - 10 : e.y
        rightClickmneun3.setBounds({ x: e.x * 1, y: y * 1, width: e.w * 1, height: e.h * 1 })
        rightClickmneun3.webContents.send('right-click-menu-3', e);
        rightClickmneun3.show()
        return
    }
    rightClickmneun3 = new BrowserWindow({
        width: 0,
        height: 0,
        x: 0, // 设置窗口的 x 坐标
        y: 0,
        modal: false,
        parent: rightClickmneun2,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        icon: '',  // 去掉图标
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    rightClickmneun3.hide();
    await rightClickmneun3.loadURL(winURL + '#/rightClickMenu3');
    WinloadingView.close()
    WinPar.show()
    rightClickmneun3.on('blur', () => {
        if (ishowrightClickmenu3 && !rightClickmneun2.isFocused() && !rightClickmneun.isFocused()) {
            hiderightClickMenu()
        }
        ishowrightClickmenu3 = false
    })
    ipcMain.on('hide-right-click-menu-3', (e, v) => {
        ishowrightClickmenu3 = false
        rightClickmneun3.hide();
    });
}

function hiderightClickMenu() {
    if (rightClickmneun) rightClickmneun.hide();
    if (rightClickmneun2) rightClickmneun2.hide();
    if (rightClickmneun3) rightClickmneun3.hide();
}


// 设置大单阈值
let dadanFazhi
function createdadanFazhi(parWin) {
    dadanFazhi = new BrowserWindow({
        width: 280,
        height: 170,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        icon: '',  // 去掉图标
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    dadanFazhi.loadURL(winURL + '#/dadanFazhi');
    ipcMain.removeAllListeners('send-dadan-fazhi')
    dadanFazhi.on('close', () => {
        dadanFazhi = null
    })
    ipcMain.on('send-dadan-fazhi', (e, v) => {
        if (v || v === 0) {
            parWin.webContents.send('right_click_msg_win', { type: '设置大单阈值', msg: v })
        }
        dadanFazhi.close()
    })
}
// 设置K线起始日期
let klineStartDate
function createklineStartDate(parWin) {
    klineStartDate = new BrowserWindow({
        width: 280,
        height: 170,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        icon: '',  // 去掉图标
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    klineStartDate.loadURL(winURL + '#/klineStartDate');
    ipcMain.removeAllListeners('send-klineStartDate')
    klineStartDate.on('close', () => {
        klineStartDate = null
    })
    ipcMain.on('send-klineStartDate', (e, v) => {
        if (v || v === '') {
            parWin.webContents.send('right_click_msg_win', { type: '指定k线起始日期', msg: v })
        }
        klineStartDate.close()
    })
}

// 资金流水窗口
let zijinLiushui
function createzijinLiushui(parWin, val) {
    if (val && zijinLiushui) {
        if (JSON.parse(val).ischurujinRefresh) {
            zijinLiushui.webContents.send('send-zijinLiushui', val);
            zijinLiushui.focus()
        } else {
            if (zijinLiushui.isVisible()) {
                zijinLiushui.hide()
            } else {
                zijinLiushui.webContents.send('send-zijinLiushui', val);
                zijinLiushui.show()
            }
        }
    } else {
        zijinLiushui = new BrowserWindow({
            width: 720,
            height: 340,
            modal: false,
            parent: parWin,
            frame: false,
            resizable: false,
            maximizable: false,  // 禁止最大化
            minimizable: false,  // 禁止最小化
            icon: '',  // 去掉图标
            webPreferences: {
                nodeIntegration: true,
                contextIsolation: false,
                enableRemoteModule: true
            }
        });
        zijinLiushui.hide()
        zijinLiushui.loadURL(winURL + '#/zijinLiushui');
        ipcMain.removeAllListeners('send-shuaxin-close')
        ipcMain.on('send-shuaxin-close', (e, v) => {
            if (v) {
                parWin.webContents.send('send-zijinLiushui—shauxin', v);
            } else {
                zijinLiushui.hide()
            }
        })
        ipcMain.removeAllListeners('send-zhanghu-yue')
        ipcMain.on('send-zhanghu-yue', (e, v) => {
            zijinLiushui.webContents.send('send-zhanghu-yue', v);
        })
        ipcMain.removeAllListeners('save-image')
        ipcMain.on('save-image', async (event, imageUrl) => {
            try {
                const { filePath } = await dialog.showSaveDialog({
                    title: '保存图片',
                    defaultPath: 'downloaded-image.png',
                    filters: [{ name: 'Images', extensions: ['png', 'jpg', 'jpeg'] }],
                });

                if (filePath) {
                    // 使用 axios 下载图片
                    const response = await axios({
                        url: imageUrl,
                        method: 'GET',
                        responseType: 'arraybuffer' // 以二进制流的形式获取数据
                    });

                    if (response.status !== 200) {
                        throw new Error(`图片下载失败，状态码：${response.status}`);
                    }

                    // 将图片保存到指定路径
                    fs.writeFile(filePath, response.data, (err) => {
                        if (err) {
                            console.error('保存图片时出错:', err);
                            event.sender.send('save-image-reply', { success: false, error: err.message });
                        } else {
                            console.log('图片保存成功:', filePath);
                            event.sender.send('save-image-reply', { success: true });
                        }
                    });
                } else {
                    event.sender.send('save-image-reply', { success: false, error: '保存取消' });
                }
            } catch (error) {
                console.error('下载或保存图片时出错:', error);
                event.sender.send('save-image-reply', { success: false, error: error.message });
            }
        });
    }

}

// 画线下单
let huaxiadanOption
function createhuaxiadanOption(parWin) {
    if (huaxiadanOption) {
        huaxiadanOption.show()
        return
    }
    huaxiadanOption = new BrowserWindow({
        width: 275,
        height: 60,
        modal: false,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    huaxiadanOption.hide()
    huaxiadanOption.loadURL(winURL + '#/huaxiadanOption');
    ipcMain.removeAllListeners('send-huaxiadanOption')
    ipcMain.on('send-huaxiadanOption', (e, v) => {
        if (huaxiadanOption) huaxiadanOption.hide()
    })
}

// 止盈止损
let sunYing
function createsunYing(parWin, val) {
    sunYing = new BrowserWindow({
        width: 400,
        height: 200,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    sunYing.loadURL(winURL + '#/sunYing');
    sunYing.webContents.on('did-finish-load', () => {
        sunYing.webContents.send('send-sunying', val)
    });
    ipcMain.removeAllListeners('send-sunYing-info')
    ipcMain.on('send-sunYing-info', (e, v) => {
        if (v) {
            parWin.webContents.send('send-sunYing-info', v)
        }
        if (sunYing) sunYing.close()
        sunYing = null
    })
}

// 止盈止损
let gongggaoinfo
async function creategongggaoinfo(parWin, val) {
    if (gongggaoinfo) {
        gongggaoinfo.webContents.send('send-gongggaoinfo-url', val)
        return;
    }
    gongggaoinfo = new BrowserWindow({
        width: 400,
        height: 190,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    await gongggaoinfo.loadURL(winURL + '#/gonggaoinfo');
    gongggaoinfo.webContents.send('send-gongggaoinfo-url', val)
    ipcMain.removeAllListeners('send-gongggaoinfo')
    ipcMain.on('send-gongggaoinfo', () => {
        if (gongggaoinfo) gongggaoinfo.close()
        gongggaoinfo = null
    })
}


// 用户评价
async function createuserevaluate(parWin) {
    let userevaluate = new BrowserWindow({
        width: 670,
        height: 470,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    await userevaluate.loadURL(winURL + '#/userevaluate');
    ipcMain.removeAllListeners('close-userevaluate')
    ipcMain.on('close-userevaluate', (e, v) => {
        if (userevaluate) userevaluate.close()
        userevaluate = null
    });
}

// 关于
async function createabout(parWin) {
    let about = new BrowserWindow({
        width: 382,
        height: 375,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    await about.loadURL(winURL + '#/about');
    ipcMain.removeAllListeners('close-about')
    ipcMain.on('close-about', (e, v) => {
        if (about) about.close()
        about = null
    });
}
// 上传日志
async function createuploadlog(parWin) {
    let uploadlog = new BrowserWindow({
        width: 418,
        height: 293,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    uploadlog.hide()
    await uploadlog.loadURL(winURL + '#/uploadlog');
    uploadlog.show()
    ipcMain.removeAllListeners('close-uploadlog')
    ipcMain.on('close-uploadlog', (e, v) => {
        uploadlog.hide()
        if (uploadlog) uploadlog.close()
        uploadlog = null
    });
}

// 运行日志
async function createruntimelog(parWin) {
    let runtimelog = new BrowserWindow({
        width: 625,
        height: 425,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    runtimelog.hide()
    await runtimelog.loadURL(winURL + '#/runtimelog');
    runtimelog.show()
    ipcMain.removeAllListeners('close-runtimelog')
    ipcMain.on('close-runtimelog', (e, v) => {
        if (runtimelog) runtimelog.close()
        runtimelog = null
    });
}

// 撤单窗口
async function createchedanview(parWin, v) {
    let chedanview = new BrowserWindow({
        width: 500,
        height: 210,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    chedanview.hide()
    await chedanview.loadURL(winURL + '#/chedanview');
    chedanview.webContents.send('chedanview-data', v)
    chedanview.show()
    ipcMain.removeAllListeners('close-chedanview')
    ipcMain.on('close-chedanview', (e, v) => {
        if (chedanview) chedanview.close()
        chedanview = null
    });
}

// 网络状态
async function createnetworkcondition(parWin, v) {
    let networkcondition = new BrowserWindow({
        width: 520,
        height: 360,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    networkcondition.hide()
    await networkcondition.loadURL(winURL + '#/networkcondition');
    networkcondition.webContents.send('networkcondition-data', v)
    networkcondition.show()
    ipcMain.removeAllListeners('close-networkcondition')
    ipcMain.on('close-networkcondition', (e, v) => {
        if (networkcondition) networkcondition.close()
        networkcondition = null
        if (networkdetail) networkdetail.close()
        networkdetail == null
    });
    createnetworkdetail(networkcondition)
}

// 优选行情服务器
async function createpreferredmarketserver(parWin) {
    let preferredmarketserver = new BrowserWindow({
        width: 520,
        height: 310,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    preferredmarketserver.hide()
    await preferredmarketserver.loadURL(winURL + '#/preferredmarketserver');
    preferredmarketserver.show()
    ipcMain.removeAllListeners('close-preferredmarketserver')
    ipcMain.on('close-preferredmarketserver', (e, v) => {
        if (preferredmarketserver) preferredmarketserver.close()
        preferredmarketserver = null
    });
}

// 网络详情
let networkdetail
async function createnetworkdetail(parWin) {
    networkdetail = new BrowserWindow({
        width: 375,
        height: 295,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    networkdetail.hide()
    await networkdetail.loadURL(winURL + '#/networkdetail');
    ipcMain.removeAllListeners('close-networkdetail')
    ipcMain.on('close-networkdetail', (e, v) => {
        if (networkdetail) networkdetail.hide()
    });
    ipcMain.removeAllListeners('open-networkdetail')
    ipcMain.on('open-networkdetail', (e, v) => {
        networkdetail.webContents.send('show-networkdetail')
        networkdetail.show()
    });
}

// 止盈止损开仓
let stopLossOpen
async function createStopLossOpen(parWin) {
    stopLossOpen = new BrowserWindow({
        width: 560,
        height: 249,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    stopLossOpen.hide()
    await stopLossOpen.loadURL(winURL + '#/stopLossOpen');
    ipcMain.removeAllListeners('close-stopLossOpen')
    ipcMain.on('close-stopLossOpen', (e, v) => {
        if (stopLossOpen) stopLossOpen.hide()
    });
    ipcMain.removeAllListeners('open-stopLossOpen')
    ipcMain.on('open-stopLossOpen', (e, v) => {
        stopLossOpen.webContents.send('show-stopLossOpen', v)
        stopLossOpen.show()
    });
}

// 条件单
let conditionList
async function createConditionList(parWin) {
    conditionList = new BrowserWindow({
        width: 500,
        height: 235,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    conditionList.hide()
    await conditionList.loadURL(winURL + '#/conditionList');
    ipcMain.removeAllListeners('close-conditionList')
    ipcMain.on('close-conditionList', (e, v) => {
        if (conditionList) conditionList.hide()
    });
    ipcMain.removeAllListeners('open-conditionList')
    ipcMain.on('open-conditionList', (e, v) => {
        conditionList.webContents.send('show-conditionList', v)
        conditionList.show()
    });
}

// 画线下单列表
let huaxianlist
async function createhuaxianlist(parWin) {
    if (huaxianlist) {
        huaxianlist.webContents.send('huaxianlist_onload')
        huaxianlist.show()
        return
    }
    huaxianlist = new BrowserWindow({
        width: 845,
        height: 365,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    huaxianlist.hide()
    await huaxianlist.loadURL(winURL + '#/huaxianlist');
    ipcMain.removeAllListeners('close-huaxianlist')
    ipcMain.on('close-huaxianlist', (e, v) => {
        if (huaxianlist) huaxianlist.hide()
    });
}

// 预警列表
let yujinglist
async function createyujinglist(parWin) {
    if (yujinglist) {
        yujinglist.webContents.send('yujinglist_onload')
        yujinglist.show()
        return
    }
    yujinglist = new BrowserWindow({
        width: 715,
        height: 365,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    yujinglist.hide()
    await yujinglist.loadURL(winURL + '#/yujinglist');
    ipcMain.removeAllListeners('close-yujinglist')
    ipcMain.on('close-yujinglist', (e, v) => {
        if (yujinglist) yujinglist.hide()
    });
}

// 预警列表
let yujingchufalist
async function createyujingchufalist(parWin) {
    if (yujingchufalist) {
        yujingchufalist.webContents.send('yujingchufalist_onload')
        yujingchufalist.show()
        return
    }
    yujingchufalist = new BrowserWindow({
        width: 486,
        height: 265,
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    yujingchufalist.hide()
    await yujingchufalist.loadURL(winURL + '#/yujingchufalist');
    ipcMain.removeAllListeners('close-yujingchufalist')
    ipcMain.on('close-yujingchufalist', (e, v) => {
        if (yujingchufalist) yujingchufalist.hide()
    });
}

// 按键精灵
let anjian
async function createanjian(parWin, v) {
    if (anjian) {
        anjian.show()
        anjian.webContents.send('anjian-onload', v)
        return
    }
    const { x, y, width, height } = parWin.getBounds();
    anjian = new BrowserWindow({
        width: 275,
        height: 340,
        x: x + width - 275,  // 右侧位置
        y: y + height - 340, // 底部位置
        modal: true,
        parent: parWin,
        frame: false,
        resizable: false,
        maximizable: false,  // 禁止最大化
        minimizable: false,  // 禁止最小化
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    anjian.hide()
    await anjian.loadURL(winURL + '#/anjian');
    ipcMain.removeAllListeners('close-anjian')
    ipcMain.on('close-anjian', (e, v) => {
        if (anjian) anjian.hide()
    });
}

// 注册
let register
async function createRegister(parWin) {
    if (register) {
        register.show()
        return
    }
    register = new BrowserWindow({
        width: 450,
        height: 650,
        modal: true,
        parent: parWin,
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });
    register.hide()
    await register.loadURL('http://146.56.245.135:8097/#/pages/login/register/register?ver=' + new Date() * 1);
    register.on('close', (e) => {
        e.preventDefault();
        register.hide()
    })
}


export { createheyueList, createRightClickmneun, hiderightClickMenu, createdadanFazhi, createklineStartDate, createzijinLiushui, createhuaxiadanOption, createsunYing, creategongggaoinfo, createuserevaluate, createabout, createuploadlog, createruntimelog, createchedanview, createnetworkcondition, createpreferredmarketserver, createStopLossOpen, createConditionList, createhuaxianlist, createyujinglist, createyujingchufalist, createanjian, createRegister };